package levels;

import mian.Game;
import utilz.LoadSave;

import java.awt.*;
import java.awt.image.BufferedImage;

public class LevelManager {
    private Level levelOne;
    private Game game;
    private BufferedImage[] levelSprite;
    public LevelManager(Game game){
        this.game=game;
        importOutsiderSprites();
        levelOne=new Level(LoadSave.GetLeveData());
    }
    public void importOutsiderSprites(){
        BufferedImage img=LoadSave.GetPlayerAtlas(LoadSave.LEVEL_ATLAS);
        levelSprite=new BufferedImage[48];
        for (int j = 0; j <4 ; j++) {
            for (int i = 0; i <12 ; i++) {
                int index=j*12+i;
                levelSprite[index]=img.getSubimage(i*32,j*32,32,32);
            }
        }
    }
    public void draw(Graphics g){
        for (int j = 0; j <Game.TILE_IN_HEIGHT ; j++) {
            for (int i = 0; i <Game.TILES_IN_WIDTH ; i++) {
                int index=levelOne.getspriteIndex(i,j);
                g.drawImage(levelSprite[index],Game.TILE_SIZE*i,Game.TILE_SIZE*j,Game.TILE_SIZE,Game.TILE_SIZE,null);
            }
        }
        g.drawImage(levelSprite[2],0,0,null);
    }
    public void update(){

    }
    public Level getCurrentLevel(){
        return levelOne;
    }

}
